package org.handyc.game.frame;

import java.awt.HeadlessException;

import javax.swing.JFrame;

import org.handyc.game.event.GameKeyListener;
import org.handyc.game.event.KeyListener;

@SuppressWarnings("serial")
public class GameFrame extends JFrame {

	public GameFrame() throws HeadlessException {
		super();

	}

	private GameKeyListener gameKeyListener;

	public void addKeyListener(KeyListener keyListener, Integer... keyCodes) {
		java.awt.event.KeyListener[] oldkeyListeners = getKeyListeners();

		boolean flag = true;
		for (java.awt.event.KeyListener oldkeyListener : oldkeyListeners) {
			if (oldkeyListener.getClass() == GameKeyListener.class) {
				flag = false;
				break;
			}
		}
		if (flag) {
			gameKeyListener = new GameKeyListener();
			addKeyListener(gameKeyListener);
		}
		gameKeyListener.addKeyListener(keyListener, keyCodes);
	}
}
